<template>
	<van-action-sheet :show="show" @close="close">
		<van-datetime-picker :type="dateTimeType" :title="actionSheetTitle" :value="new Date().getTime()"
			:min-date="new Date(1900, 1, 1).getTime()" :max-date="new Date(2099, 10, 1).getTime()" @confirm="submit"
			@cancel="close" />
	</van-action-sheet>
</template>

<script setup lang="ts">
	import { getOrderList } from '@/api/user';
	import { Utils } from '@/utils/utils';
	import { onShow } from '@dcloudio/uni-app';
	import { ref, watch } from 'vue';
	const props = defineProps({
		show: {
			type: Boolean,
			default: false,
		},
		title: {
			type: String,
			default: '请选择',
		},
		// 弹窗类型
		type: {
			type: String,
			default: '',
		},

		// 选择时间类型，可选值为 date time year-month
		dateTimeType: {
			type: String,
			default: 'date',
		},
		// 父页面标题
		pageTitle: {
			type: String,
			default: '',
		},

	});
	// 弹出标题
	const actionSheetTitle = ref('请选择');
	// 监听show属性变化，获取数据
	watch(
		() => props.show,
		() => {
			if (props.show) {
				actionSheetTitle.value = '请选择' + props.type;

			}
		}
	);
	// 组件回调
	const emit = defineEmits(['radioChange', 'close', 'submit']);
	// 关闭弹窗
	const close = () => {
		emit('close');
	};
	// 确定
	const submit = (e) => {
		const dateTimeType = props.dateTimeType
		let dateTimeText = ''
		// 根据时间类型判断返回日期格式
		switch (dateTimeType) {
			case 'date':
				dateTimeText = Utils.formatDate(Number(e.detail))
				break;
			default:
				dateTimeText = Utils.formatTimestamp(Number(e.detail))
		}
		emit('submit',dateTimeText);
		close()
	};
</script>

<style lang="less" scoped>
	.specification_btn {
		view {
			flex: 1;
			padding: 20rpx 0;
			border-radius: 10rpx;
			border: 1px solid #3975f6;
			background: #3975f6;
			font-weight: 500;
			font-size: 28rpx;
			text-align: center;
			color: #fff;
		}
	}

	.item {
		display: flex;
		margin-bottom: 8rpx;

		.key {
			color: #666;
		}

		.value {
			flex: 1;
			font-weight: 500;
		}
	}
</style>